#include "fleets.h"
using namespace combat;

//BULLET_____________________________________________________________
/**
 * bullet - a container to hold damage and
 * accuracy values of a bullet
 */

/**
 * bullet constructor - takes the two values
 * assosiated with a bullet and makes a bullet
 * @param d the damage a bullet does
 * @param a the accuracy fo teh shot
 */
bullet::bullet(int d, int a){
    damage = d;
    accuracy = a;
}
/**
 * dam - get the damage value of bullet
 * @return returns the damage
 */
int bullet::dam(){
    return damage;
}
/**
 * acc - gets the acc of teh bullet
 * @return returns accuracy value
 */
int bullet::acc(){
    return accuracy;
}
/**
 * operator== - compares two bullets
 * @return returns true if the dam and acc values are the same
 */
bool bullet::operator ==(bullet& b){
    return (damage == b.dam()) && (accuracy == b.acc());
}

//BATTERY____________________________________________________________
/**
 * battery - essentialy a bullet factory. only one bullet is made for
 * each batery and that struct is passed about
 */

/**
 * battery - constructor - creates a battery and
 * assigns it its bullet
 * @param d bullet damage
 * @param a bullet acc
 * @param minr the minimum range of the gun
 * @param maxr the maximum range of the gun
 * @param acost the ap cost to shoot
 * @param scost the salvo cost to shoot
 */
battery::battery(int d, int a, int minr, int maxr, int acost, int scost) : b(d, a){
    minRange = minr;
    maxRange = maxr;
    apc = acost;
    sc = scost;
}

/**
 * shoot - checks to see if the params are valid,
 * then gives a bullet
 *
 * @param ap the ap pool
 * @param salvos the salvo pool
 * @param range rang to target
 */
bullet* battery::shoot(int* ap, int* salvos, int range){
    if(range < minRange || range > maxRange) return NULL;
    if(*ap < apc) return NULL;
    if(*salvos < sc) return NULL;
    (*ap) -= apc;
    (*salvos) -= sc;
    return &b;
}

//combatabt__________________________________________________________

/**
 * an interface to describe how units fight one another
 * It provides a few static funtions to help
 */

/**
 * range returns the range from the source coords to the dest coords
 * @param sx source x
 * @param sy source y
 * @param dx dest z
 * @param dy dest y
 * @return returns the range
 */
int combatant::range(int sx, int sy, int dx, int dy){
    return sqrt((sx - dx) * (sx - dx) + (sy - dy) * (sy - dy));
}

/**
 * returns the direction the dest is to the source.
 * @param sx source x
 * @param sy source y
 * @param dx dest x
 * @param dy dest y
 * @return returns the driection from source to dest
 */

direction combatant::relation(int sx, int sy, int dx, int dy){
    dx -= sx;
    dy -= dy;
}

/**
 * shoot generates a voley from source and applies the
 * voley to the targ.takedamage function 
 *
 * @param source the shooter
 * @param targ the target to be shot
 */
void combatant::shoot(combatant* source, combatant* targ){
    source->shoot(targ);
}

//officer____________________________________________________________

/**
 * the officer is the named leader of a strike cell
 * or fleet.  It modifies the stats of what it is attatched
 * to allowing for further customization of units.
 */
/**
 * officer - inisializes an officer
 * @param pow buff to the power stat
 * @param spd buff to the speed stat
 * @param cohes buff to the cohes stat
 * @param name the name of the officer
 */
officer::officer(int _pow, int _spd, int _cohes, string _name){
    pow = _pow;
    spd = _spd;
    cohes = _cohes;
    name = _name;
}

int officer::gPow(){
    return pow;
}
int officer::gSpd(){
    return spd;
}
int officer::gCohes(){
    return cohes;
}